//
//  NSArray+JSON.m
//  CTalk
//
//  Created by Gao Yongqing on 9/26/15.
//  Copyright © 2015 Chinac.com. All rights reserved.
//

#import "NSArray+JSON.h"

@implementation NSArray(JSON)

- (NSString*)jsonString
{
    NSData* infoJsonData = [NSJSONSerialization dataWithJSONObject:self options:NSJSONWritingPrettyPrinted error:nil];
    NSString* json = [[NSString alloc] initWithData:infoJsonData encoding:NSUTF8StringEncoding];
    return json;
}

+ (NSArray *)arrayWithJsonString:(NSString*)json
{
    NSData* infoData = [json dataUsingEncoding:NSUTF8StringEncoding];
    NSError *error = nil;
    NSArray *array = [NSJSONSerialization JSONObjectWithData:infoData options:0 error:&error];
    if (error) {
        NSLog(@"Create array from json string:%@ error:",json);
    }
    return array;
}

@end
